package top.hencter.weibo.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import java.util.List;

import top.hencter.weibo.R;
import top.hencter.weibo.adapter.*;

public class PhotoViewActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_view);

        Intent intent = getIntent();

        List<String > images = (List<String>)intent.getSerializableExtra("images");
        int currentItem = intent.getIntExtra("currentItem", 0);

        ViewPager viewPager = findViewById(R.id.photo_view_page);

        // 关联 Adapter 和 viewPager
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(this, images);
        viewPager.setAdapter(viewPagerAdapter);

        // 设置 viewPager 需要显示的项
        viewPager.setCurrentItem(currentItem);

        // 结束 Activity
        viewPager.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}